package cn.yunyichina.reservation.controller;

import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.reservation.common.ResponseEnum;
import cn.yunyichina.reservation.constant.HttpResponse;
import cn.yunyichina.reservation.constant.Interface;

/**
 * Created by adriftor
 */
public class BaseResponseController extends BaseController {

    public HttpResponse toHttpResponse(Response response) {
        HttpResponse httpResponse = new HttpResponse();
        if (response == null) {
            return httpResponse.failure(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMessage());
        }
        if (Interface.SUCCESS.equals(response.getResultCode())) {
            httpResponse.setData(response.getResult() == null ? "" : response.getResult());
        } else {
            httpResponse.failure(response.getResultCode(), response.getResultMessage());
        }
        return httpResponse;
    }

}
